<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <title>新增驱动</title>
    <link rel="shortcut icon" type="image/x-icon" th:href="@{/static/img/favicon.ico}" media="screen"/>
    <link rel="stylesheet" th:href="@{/static/css/layui.css}" media="all"/>
</head>
<body>
<div class="layui-field-box">
    <form class="layui-form" action="" id="addFrom">
        <div class="layui-inline">
            <div class="layui-form-item">
                <label class="layui-form-label">驱动名称</label>
                <div class="layui-input-block">
                    <input type="text" name="name" id="name" lay-verify="required" autocomplete="off" lay-affix="clear"
                           th:value="${object.name}"
                           placeholder="请输入驱动名称" class="layui-input">
                    <input type="hidden" name="id" id="id" autocomplete="off" th:value="${object.id}">
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">驱动类名</label>
            <div class="layui-input-block">
                <input type="text" name="driverClass" id="driverClass" lay-verify="required" autocomplete="off"
                       th:value="${object.driverClass}"
                       lay-affix="clear"
                       placeholder="请输入驱动类" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">连接地址</label>
            <div class="layui-input-block">
                <input type="text" name="url" id="url" lay-verify="required" lay-affix="clear" th:value="${object.url}"
                       placeholder="请输入连接地址" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">有效性</label>
            <div class="layui-input-block">
                <input type="text" name="dbCheckUrl" id="dbCheckUrl" lay-verify="required" placeholder="请输入有效性"
                       th:value="${object.dbCheckUrl}"
                       lay-affix="clear"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">驱动类型</label>
                <div class="layui-input-block">
                    <input type="text" name="typeName" id="typeName" placeholder="请输入数据库登录账号" readonly
                           th:value="${object.typeName}=='内置' ? '内置':'自定义' "
                           lay-affix="clear"
                           autocomplete="off" class="layui-input">
                </div>
            </div>
        </div>
        <div class="page-footer">
            <div class="btn-list">
                <div class="btnlist">
                    <button class="layui-btn layui-btn-primary layui-border-green" lay-submit lay-filter="save"
                            lay-type="saveContinue">
                        <i class="layui-icon  layui-icon-add-circle">&nbsp;</i>保存并继续
                    </button>
                    <button class="layui-btn layui-btn-primary layui-border-blue" lay-submit lay-filter="save"
                            lay-type="saveClose">
                        <i class="layui-icon layui-icon-add-1">&nbsp;</i>保存并关闭
                    </button>
                    <button class="layui-btn layui-btn-primary layui-border-red" onclick="refresh();">
                        <i class="layui-icon layui-icon-close-fill">&nbsp;</i>关闭
                    </button>
                </div>
            </div>
        </div>
    </form>

</div>
<script th:src="@{/static/layui.js}"></script>
<script th:replace="~{base::ctx}"></script>
<script>

    layui.use(['jquery', 'layer', 'form'], function () {
        const layer = layui.layer;
        const form = layui.form;
        const $ = layui.jquery;

        /**
         * 保存
         */
        form.on('submit(save)', function (data) {
            const field = data.field;
            const elem = data.elem;
            let layType = elem.getAttribute("lay-type");
            post(ctx + "settingManager/saveOrUpdateDriverConfig", field, (res) => {
                layer.msg(res.msg, {icon: res.code === 200 ? 1 : 2}, () => {
                    if (res.code === 200) {
                        if (layType === "saveClose") {
                            refresh();
                        } else {
                            location.reload();
                        }
                    }
                });
            })
            return false;
        });

    });
</script>
</body>
</html>
